import 'package:flutter/material.dart';
import 'package:xws/utils/theme_util.dart';

import 'app_btn.dart';

/// 图标按钮
class ActionIcon extends StatelessWidget {
  const ActionIcon({
    Key? key,
    required this.icon,
    required this.actionIcon,
    this.unSelectColor,
    this.activeColor,
    this.content,
    this.isSelect = false,
    this.onTap,
    this.iconSize,
    this.padding,
  }) : super(key: key);

  final IconData icon;
  final IconData actionIcon;
  final Color? unSelectColor;
  final Color? activeColor;
  final String? content;
  final bool isSelect;

  final Function()? onTap;

  final double? iconSize;

  final EdgeInsetsGeometry? padding;

  @override
  Widget build(BuildContext context) {
    return AppBtn.center(
      onTap: onTap,
      color: Colors.transparent,
      disabledColor: Colors.transparent,
      child: Row(
        mainAxisAlignment: MainAxisAlignment.center,
        children: <Widget>[
          Icon(isSelect ? actionIcon : icon,
              size: iconSize ?? 18, color: _color(context)),
          const SizedBox(width: 6),
          Text(
            content ?? '',
            style: TextStyle(
              color: _color(context),
              fontSize: 14,
            ),
          ),
        ],
      ),
      radius: 0,
      padding: padding ?? EdgeInsets.zero,
    );
  }

  Color _color(BuildContext context) {
    return isSelect
        ? (activeColor ?? theme(context))
        : (unSelectColor ?? disable(context));
  }
}
